# gozerlib/wave/waves.py
#
#

""" class to repesent a wave. """

## gozerlib imports

from gozerlib.channelbase import ChannelBase

## waveapi imports 

from waveapi import robot_abstract

## 

from simplejson import dumps

## basic imports

import logging
import copy

cpy = copy.deepcopy

class Wave(ChannelBase):

    """ a wave is seen as a channel. """

    def parse(self, properties, context):

        """ parse event into a Wave. """

        self.properties = cpy(properties)
        self.context = cpy(context)
        self.serialized = self.context.Serialize()
        self.root = context.GetRootWavelet()
        self.waveid = self.root.waveId
        logging.debug("parsed %s (%s) channel" % (self.name, self.root.title))
        return self

    def say(self, txt):

        """ output some txt to the wave. """

        #logging.debug("context: %s" % dir(self.context))
        root = self.context.GetRootWavelet()
        blip = root.CreateBlip()
        doc = blip.GetDocument()
        doc.SetText(txt)
        #logging.debug("output to %s: %s" % (self.waveid, self.context.Serialize()))
        #logging.debug("result: %s %s %s" % (root, blip, doc))

